package com.xiaoKe.zhonghzu.ui.mine;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.xiaoKe.zhonghzu.R;
import com.xiaoKe.zhonghzu.databinding.FragmentMineBinding;
import com.xiaoKe.zhonghzu.global.base.BaseFragment;
import com.xiaoKe.zhonghzu.global.base.VeinRouter;
import com.xiaoKe.zhonghzu.global.bean.FastBean;
import com.xiaoKe.zhonghzu.global.tool.SPUtils;
import com.xiaoKe.zhonghzu.ui.login.LoginActivityPwsWord;
import com.xiaoKe.zhonghzu.ui.onClick.NoDoubleClickListener;
import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionInt;

import java.util.ArrayList;
import java.util.List;


/**
 * @ProjectName : app
 * @Author : Shijingna
 * @Time : 2022/9/28 11:35 上午
 * @Description : 我的总览
 */
public class MineFragment extends BaseFragment<FragmentMineBinding> {
    private List<FastBean> list;

    @Override
    protected void initView() {
        //扫一扫
        NoDoubleClickListener noDoubleClickListener = new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View view) {
                switch (view.getId()) {
                    case R.id.quit://退出登录
                        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                        builder.setTitle("提示")
                                .setMessage("确定要退出登录？")
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        // 处理确定按钮的点击事件
                                        SPUtils.putString("token","");
                                        startActivity(new Intent(getContext(), LoginActivityPwsWord.class));
                                        getActivity().finish();
                                    }
                                })
                                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        // 处理取消按钮的点击事件
                                    }
                                })
                                .setCancelable(false) // 设置对话框不可取消
                                .show(); // 显示对话框


                        break;
                }
            }
        };
        binding.quit.setOnClickListener(noDoubleClickListener);
        binding.swipeRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    @Override
    protected void initData() {
        MineAdapter mineAdapter = new MineAdapter();
        list = new ArrayList<>();
        list.add(new FastBean(getString(R.string.修改密码), R.mipmap.ic_password, "password"));
//        list.add(new FastBean("修改手机号", R.mipmap.ic_phone, "phone"));
        list.add(new FastBean(getString(R.string.系统设置), R.mipmap.ic_set, "set"));
        mineAdapter.setData(list);
        binding.swipeRecyclerView.setAdapter(mineAdapter);
        mineAdapter.setOnClickListenerPositionInt(new OnClickListenerPositionInt() {
            @Override
            public void onItemClick(int item) {
                Bundle bundle = new Bundle();
                String name = list.get(item).getName();
                bundle.putString("titleName", name);
                String content = list.get(item).getContent();
                switch (content) {
                    case "password":
                        toFragmentPage(VeinRouter.CHANGEPASSWORDFRAGMENT.setBundle(bundle));
                        break;
                    case "phone":
                        toFragmentPage(VeinRouter.PHONEPASSWORDFRAGMENT.setBundle(bundle));
                        break;
                    case "set":
                        toFragmentPage(VeinRouter.REGARDFRAGMENT.setBundle(bundle));
                        break;


                }
            }
        });

    }


}
